{extend name="admin/public:layout" /}
{block name="title"}会议企业管理{/block}
{block name="head"}
<script src="/public/plugins/template/template.js"></script>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 会议企业管理</a></li>
                <li class="active">添加会议企业</li>
            </ol>
        </div>
        <div class="ibox-content form-horizontal">
            <form method="post" class="form-horizontal" id="form">
                {empty name="meetingId"}
                <input type="hidden" class="form-control" value="" id="meetingId" />
                {else/}
                <input type="hidden" class="form-control" value="{$meetingId}" id="meetingId" />
                {/empty}
            </form>
            <div class="form-group">
                <label class="col-sm-2 control-label Validform_label">检索所需企业名称</label>
                <div class="col-sm-4">
                    <form class="form-inline" method="post">
                        <div class="form-group">
                            <div class="input-group">
                                <input class="form-control" name="company_name" id="companyName" value="" type="text" placeholder="检索企业名称,空检索全部">
                            </div>
                        </div>
                        <button type="button" class="btn btn-info" onclick="secom()">
                            <i class="fa fa-search"></i> 搜索
                        </button>
                    </form>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label Validform_label">选定会议</label>
                <div class="col-sm-4">
                    <select class="form-control" name="meeting_id" id="meeting_id">
                        <option>请选择要操作的会议</option>
                        {volist name="meetingList" id="vo"}
                        <option value="{$vo.meeting_id}" {eq name="meetingId" value="$vo['meeting_id']"}selected{/eq}>{$vo.meeting_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label Validform_label">企业列表</label>
                <div class="col-sm-4">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th width="50">#</th>
                            <th>企业名称</th>
                            <th width="180">操作</th>
                        </tr>
                        </thead>
                        <tbody id="com">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="comList">
    {{ each data as vo}}
    <tr>
        <td>{{ vo.company_id }}</td>
        <td>{{ vo.company_name }}</td>
        <td>
            <a href="javascript:;" onclick="delcom(this);" data-params="{{ vo.company_id }}">添加到会议</a>
        </td>
    </tr>
    {{ /each}}
</script>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        formatDate();
        ajaxSubForm('#btnSub');
    })
    var meeting_id = $("#meeting_id").val();
    $.post("{:url('comList')}",{meeting_id: meeting_id},function (res) {
        var comList = template('comList', {data: res});
        $('#com').html(comList);
    });
    $("#meeting_id").change(function(){
        var meeting_id = $("#meeting_id").val();
        $('#meetingId').val(meeting_id);
        $.post("{:url('comList')}",{meeting_id: meeting_id},function (res) {
            var comList = template('comList', {data: res});
            $('#com').html(comList);
        });
    });
    function secom(){
        var companyName = $("#companyName").val();
        var meeting_id = $("#meeting_id").val();
        $('#meetingId').val(meeting_id);
        $.post("{:url('comList')}",{meeting_id: meeting_id,company_name: companyName},function (res) {
            var comList = template('comList', {data: res});
            $('#com').html(comList);
        });
    }
    function delcom(obj){
        var company_id = $(obj).data('params');
        var meeting_id = $("#meeting_id").val();
        $.post('{:url("add")}', {company_id: company_id,meeting_id: meeting_id}, function (res) {
            if (res.code==1) {
                $(obj).closest('tr').remove();
            }
        });
    }
</script>
{/block}